/**
 * Created by Administrator on 2016/8/11.
 */
define(["require",'config/appregister',
    "business/workSkill/services/httpServices",
   "business/workSkill/directive/startLevel","business/services/commentComp"],function(require,app,httpServices){
    app.controller('workDetailsCtrl',function($scope,$stateParams,$state,$rootScope){
        /*星级*/
        $scope.goto = function(item,Id,ctrl){
			$state.go(ctrl,{postbarId:Id})
		}
        $scope.linkSearch=function(name){
            $rootScope.GLOBALKEYWORD =  name;
            sessionStorage.searchKeyWord = name;
            $state.transitionTo("search.skill", {}, {
                reload: true, inherit: false, notify: true
            });
        }
        $scope.max = 5;//最大星级
        $scope.ratingVal = 3;///默认星级，必需设置，下面同样名字覆盖，否则不显示；
        $scope.readonly = true;//false可编辑，true不可编辑
        $scope.onHover = function(val){
            $scope.hoverVal = val;
        };
        $scope.onLeave = function(){
            $scope.hoverVal = null;
        }
        $scope.onChange = function(val){
            $scope.ratingVal = val;
        };

        $scope.$parent.isDetailPage = true;
        $scope.$parent.isMainpage = false;
        $scope.tab = 1; // 默认显示第1个tab内容
        /*判断如果有dataid加载数据*/
        if($stateParams.skillId){
            var id = $stateParams.skillId;
            /*技能头部能容*/
            function getSkillCon(){
                var req ={
                    type:"GET",
                    uri:"get",
                    data:{
                        skillId:id
                    }
                };
                httpServices.getConctent(req).success(function(response){
                    $scope.$apply(function(){
                        /*头部内容部分*/
                        $scope.title = response.data.skill.title;//标题
                        $scope.titleId = response.data.skill.skillId;//id
                        $scope.details = response.data.skill.introduction;//描述
                        $scope.visters = response.data.skill.visitCount;//多少人浏览
                        $scope.evaNum = response.data.skill.commentCount;//多少人评价
                        $scope.Num = response.data.skill.videoSize//多少个视频
                        $scope.datacount = response.data.skill.dataCount//多少个资料
                        $scope.ratingVal = response.data.skill.avgCount;//星级
                        $scope.category = response.data.category;
                        $scope.thId = response.data.category.tcId;
                        $scope.logoImg = response.data.skill.previewPath;
                        $scope.labelList = response.data.skill.labelList;
                    })
                });
            }
            $scope.goList=function(){
                $state.go("eng.workListCtrl")
            }
            $scope.goEcho=function(){
                $state.go("eng.workListCtrl")
                sessionStorage.worlListId =$scope.thId;
            }
            /*资料目录内容*/
            function getCate(){
                var req ={
                    type:"GET",
                    uri:"getSigleSkillFile",
                    data:{
                        count:10,
                        skillId:id
                    }
                };
                httpServices.getConctent(req).success(function(response){
                    $scope.$apply(function(){
                        $scope.DataCate = response.data.list;
                    })
                });
            }
            /*视频目录内容*/
            function getVideoCata(){
                var req ={
                    type:"GET",
                    uri:"getSigleSkillVideo",
                    data:{
                        count:10,
                        skillId:id
                    }
                };
                httpServices.getConctent(req).success(function(response){
                    $scope.$apply(function(){
                        $scope.VideoCate = response.data.list;
                    })
                });
            }
            /*相关资料*/
            function sameData(){
                var req ={
                    type:"GET",
                    uri:"getSameSkill",
                    data:{
                        pageNo:1,
                        pageSize:8,
                        skillId:$stateParams.skillId
                    }
                };
                httpServices.getConctent(req).success(function(response){
                    $scope.$apply(function(){
                        $scope.sameData = response.data.list;
                    })
                });
            }
            getSkillCon();
            getCate();
            getVideoCata();
            sameData();
        }

        /*评价*/
        $scope.commentConf = {
            showStar: true,
            tbWidth:745,
            conf: {
                id: $stateParams.skillId,
                type: 7
            }
        };


        /*视频目录跳转*/
        $scope.switchVideo=function(item){
            $state.go("vedioDetails",{tempId:item.videoId})
        };
        $scope.goData=function(item){
            $state.go("eng.techdetail",{fileId:item.fileId})
        }
    });
});

